package com.example.zjsr.util;

import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import okhttp3.*;

import java.io.*;

public class PostUtilInto {

        public static String formUpload(String REQUEST_PATH,String filePath,String fileName) {
            String res="";
            try {
                OkHttpClient client = new OkHttpClient().newBuilder()
                        .build();
                MediaType mediaType = MediaType.parse("text/plain");
                RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
                        .addFormDataPart("data",fileName,
                                RequestBody.create(MediaType.parse("application/octet-stream"),
                                        new File(filePath)))
                        .build();
                Request request = new Request.Builder()
                        .url(REQUEST_PATH)
                        .method("POST", body)
                        .build();
                Response response = client.newCall(request).execute();
                System.out.println("response"+response);
                System.out.println("code"+response.code());
                res=response.code()+"";
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }

        public static void excelToPdf(String filePath,String pdfFilePath){
            Workbook wb = new Workbook();
            wb.loadFromFile(filePath);
            //调用方法保存为PDF格式
            wb.saveToFile(pdfFilePath, FileFormat.PDF);
            System.out.println("asdfasd");
        }

    public static void main(String[] args) {
//         String filePath="C:\\Users\\wanghui\\Desktop\\1622690938592.xlsx";
//         String pdfFilePath="C:\\Users\\wanghui\\Desktop\\batch_upload_student_demo2.pdf";
//        excelToPdf(filePath,pdfFilePath);
        Workbook wb = new Workbook();
        wb.loadFromFile("C:\\Users\\wanghui\\Desktop\\mj_802068.xlsx");
        //调用方法保存为PDF格式
        //获取工作表
        Worksheet sheet = wb.getWorksheets().get(0);

        //调用方法将Excel工作表保存为图片
        wb.saveToFile("C:\\Users\\wanghui\\Desktop\\ToPDF2.pdf", FileFormat.PDF);

    }
}
